<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      label-width="auto"
      v-show="showSearch"
    >
      <el-row>
        <el-form-item label="生产类别" prop="type">
          <el-select
            style="width: 180px"
            filterable
            v-model="queryParams.type"
            placeholder="请选择生产类别"
          >
            <el-option
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="生产单编码" prop="produceNo">
          <el-input
            v-model.trim="queryParams.produceNo"
            style="width: 180px"
            placeholder="请输入生产单编码"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="日期" style="width: 308px">
          <el-date-picker
            v-model="dateRange"
            value-format="YYYY-MM-DD"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>

        <div class="operation">
          <el-button type="primary" icon="Search" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          <el-button @click="advanced = !advanced">
            <a style="color: #448ef7">
              <el-icon v-if="advanced">
                <ArrowUpBold />
              </el-icon>
              <el-icon v-else>
                <ArrowDownBold />
              </el-icon>
            </a>
          </el-button>
        </div>
      </el-row>
      <el-row v-if="advanced">
        <el-form-item label="产品名称" prop="productName">
          <el-input
            v-model.trim="queryParams.productName"
            style="width: 180px"
            placeholder="请输入产品名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select
            style="width: 180px"
            filterable
            v-model="queryParams.status"
            placeholder="请选择状态"
          >
            <el-option
              v-for="item in ems_order_status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="定量" prop="weight">
          <el-input
            v-model.trim="queryParams.weight"
            style="width: 180px"
            placeholder="请输入定量"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="下单日期" prop="submitDate">
          <el-date-picker
            style="width: 180px"
            v-model="queryParams.submitDate"
            value-format="YYYY-MM-DD "
            type="date"
            placeholder="请选择日期"
          />
        </el-form-item>
      </el-row>
    </el-form>
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"></el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
        :columns="columns"
      ></right-toolbar>
    </el-row> -->
    <div>
      <el-table
        v-loading="loading"
        row-key="produceId"
        :summary-method="getSummaries"
        height="65vh"
        show-summary
        @selection-change="handleSelectionChange"
        border
        :data="dataList"
      >
        <el-table-column type="selection" align="center" width="40" />
        <el-table-column label="序号" width="60" type="index" align="center" />
        <el-table-column
          label="状态"
          min-width="100"
          align="center"
          :show-overflow-tooltip="true"
          prop="status"
          v-if="columns[0].visible"
        >
          <template v-slot="{ row }">
            <dict-tag :options="ems_order_status" :value="row.status" />
          </template>
        </el-table-column>
        <el-table-column
          label="生产单编码"
          width="180"
          align="center"
          :show-overflow-tooltip="true"
          prop="orderNo"
          v-if="columns[1].visible"
        >
          <template v-slot="{ row }">
            <el-button type="primary" @click="handleView(row)" text>
              {{ row.produceNo }}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="出版编号"
          min-width="120"
          align="center"
          :show-overflow-tooltip="true"
          prop="pubNo"
          v-if="columns[3].visible"
        ></el-table-column>
        <!-- <el-table-column
          label="产品名称"
          min-width="160"
          align="center"
          prop="productName"
          v-if="columns[3].visible"
        ></el-table-column> -->

        <el-table-column
          label="产品名称"
          min-width="240"
          align="center"
          prop="productName"
          v-if="columns[3].visible"
        >
          <template v-slot="{ row }">
            <el-button type="primary" @click="handleViewys(row)" text>
              {{ row.productName }}
            </el-button>
          </template>
        </el-table-column>

        <el-table-column
          label="订单数量"
          width="100"
          align="center"
          prop="orderCount"
          v-if="columns[3].visible"
        >
        <template v-slot="{ row }">
           <span v-if="row.type==2">
              {{ row.orderCount }}
           </span>
           <span v-else
              v-for="(item, index) in row.produceCount?.split(',')"
              :key="index"
            >
              {{ item }}
           </span>
          </template>
      </el-table-column>
        <el-table-column
          label="书号"
          width="120"
          align="center"
          prop="bookNo"
        />
        <el-table-column
          label="下单日期"
          min-width="120"
          align="center"
          :show-overflow-tooltip="true"
          prop="submitDate"
          v-if="columns[4].visible"
        >
          <template v-slot="{ row }">
            {{ row.submitDate?.split("T")[0] ?? "" }}
          </template>
        </el-table-column>
        <el-table-column
          label="交货日期"
          min-width="120"
          align="center"
          :show-overflow-tooltip="true"
          prop="deliverDate"
          v-if="columns[5].visible"
        >
          <template v-slot="{ row }">
            {{ row.deliverDate?.split("T")[0] ?? "" }}
          </template>
        </el-table-column>
        <el-table-column
          label="备注"
          min-width="120"
          align="center"
          :show-overflow-tooltip="true"
          prop="remark"
        >
          <template v-slot="{ row }"
            >{{ row.changePiece }} {{ row.remark }}</template
          >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :pageSizes="[10, 20, 30, 50, 100, 200, 500]"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <el-divider content-position="left">用纸信息</el-divider>
    <el-table
      v-loading="paperLoading"
      height="65vh"
      :data="producePaperList"
      border
    >
      <el-table-column label="序号" width="60" type="index" align="center" />
      <!-- <el-table-column
                label="纸张序列号"
                min-width="120"
                prop="paperProduceNo"
                align="center"
            ></el-table-column> -->
      <el-table-column
        label="纸张编码"
        min-width="120"
        prop="paperNo"
        align="center"
      ></el-table-column>

      <el-table-column label="纸张类型" prop="type" width="120" align="center">
        <template #default="scope">
          <dict-tag :options="mes_paper_material" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column
        label="纸张名称"
        min-width="150"
        prop="paperName"
        align="center"
      />
      <el-table-column label="纸型" width="100" prop="paperType" align="center">
        <template #default="scope">
          <dict-tag :options="mes_paper_type" :value="scope.row.paperType" />
        </template>
      </el-table-column>
      <el-table-column
        label="定量"
        width="100"
        prop="weight"
        align="center"
      ></el-table-column>
      <el-table-column
        label="规格"
        min-width="120"
        prop="specifications"
        align="center"
      >
        <template #default="scope">
          <dict-tag
            :options="mes_paper_specs"
            :value="scope.row.specifications"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="幅宽(mm)"
        width="100"
        prop="length"
        align="center"
      ></el-table-column>
      <el-table-column label="单位" min-width="120" prop="unit" align="center">
        <template #default="scope">
          <dict-tag :options="mes_paper_unit" :value="scope.row.unit" />
        </template>
      </el-table-column>
      <el-table-column
        label="当时库存"
        width="120"
        prop="amount"
        align="center"
      ></el-table-column>
      <el-table-column
        label="数量"
        min-width="120"
        prop="reamAmount"
        align="center"
      ></el-table-column>
      <!-- <el-table-column
                label="裁切尺寸"
                width="100"
                prop="size"
                align="center"
            ></el-table-column> -->
      <el-table-column
        label="版材尺寸"
        width="100"
        prop="sheetSize"
        align="center"
      >
        <template #default="scope">
          <dict-tag
            :options="ems_machine_info_size"
            :value="scope.row.sheetSize"
          />
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      v-model="open"
      title="产品信息"
      width="70%"
      @close="handleCancel"
    >
      <el-table
        v-if="type == 1"
        v-loading="loadingList"
        :data="produceProductList"
        border
      >
        <el-table-column label="序号" width="60" type="index" align="center" />
        <el-table-column
          label="产品序列号"
          min-width="120"
          prop="productNo"
          align="center"
        ></el-table-column>
        <el-table-column
          label="订单数量"
          width="120"
          prop="produceCount"
          align="center"
        ></el-table-column>
        <el-table-column
          label="书刊编码"
          min-width="120"
          prop="bookCode"
          align="center"
        ></el-table-column>
        <el-table-column
          label="书刊名称"
          min-width="160"
          prop="bookName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="产品品种"
          prop="breedType"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          label="清样编号"
          min-width="120"
          prop="sampleNo"
          align="center"
        ></el-table-column>
        <el-table-column
          label="文件号"
          min-width="120"
          prop="fileNo"
          align="center"
        ></el-table-column>
        <el-table-column
          label="书号"
          min-width="120"
          prop="bookNo"
          align="center"
        ></el-table-column>
        <el-table-column
          label="定价"
          min-width="120"
          prop="fixPrice"
          align="center"
        ></el-table-column>
        <el-table-column
          label="组成"
          min-width="120"
          prop="composition"
          align="center"
        ></el-table-column>
        <el-table-column
          label="印色"
          min-width="100"
          prop="printColor"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_order_print_color"
              :value="scope.row.printColor"
            />
          </template>
        </el-table-column>
        <el-table-column label="颜色" width="130" prop="color" align="center">
          <template #default="scope">
            <dict-tag :options="ems_produce_color" :value="scope.row.color" />
          </template>
        </el-table-column>
        <el-table-column
          label="纸型"
          width="120"
          prop="paperType"
          align="center"
        >
          <template #default="scope">
            <dict-tag :options="mes_paper_type" :value="scope.row.paperType" />
          </template>
        </el-table-column>
        <el-table-column
          label="纸张编码"
          width="120"
          prop="paperNo"
          align="center"
        ></el-table-column>

        <el-table-column
          label="用纸尺寸"
          prop="paperSize"
          width="120"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_produce_paper_size"
              :value="scope.row.paperSize"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="纸张名称"
          width="120"
          prop="paperName"
          align="center"
        />
        <el-table-column
          label="覆膜"
          width="120"
          prop="coverFilm"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_produce_cover_film"
              :value="scope.row.coverFilm"
            />
          </template>
        </el-table-column>

        <el-table-column label="喷码" width="100" prop="marking" align="center">
          <template #default="scope">
            <dict-tag
              :options="ems_produce_marking"
              :value="scope.row.marking"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="联版数量"
          width="120"
          prop="lianbanCount"
          align="center"
        ></el-table-column>
        <el-table-column
          label="内文承印厂"
          width="120"
          prop="textPrinter"
          align="center"
        >
          <!-- <template #default="scope">
                        <dict-tag :options="produce_text_printer" :value="scope.row.textPrinter" />
                    </template> -->
        </el-table-column>
        <el-table-column
          label="客户名称"
          width="120"
          prop="customerName"
          align="center"
        ></el-table-column>

        <el-table-column
          label="科目"
          width="100"
          prop="subjectType"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_workshop_subject_type"
              :value="scope.row.subjectType"
            />
          </template>
        </el-table-column>
      </el-table>
      <el-table
        v-else
        v-loading="loadingList"
        class="myTable"
        :data="produceProductList"
        border
      >
        <el-table-column label="序号" width="60" type="index" align="center" />
        <el-table-column
          label="订单数量"
          width="100"
          prop="produceCount"
          align="center"
        ></el-table-column>

        <el-table-column
          label="品种"
          prop="breedType"
          width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          label="装订方式"
          width="140"
          prop="bindingMode"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_order_binding_mode"
              :value="scope.row.bindingMode"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="开本数"
          width="100"
          prop="bookSize"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_produce_book_size"
              :value="scope.row.bookSize"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="组成"
          width="100"
          prop="composition"
          align="center"
        ></el-table-column>
        <el-table-column
          label="详细信息"
          min-width="120"
          prop="detail"
          align="center"
        ></el-table-column>
        <el-table-column
          label="贴数信息"
          width="200"
          prop="piece"
          align="center"
        ></el-table-column>
        <el-table-column
          label="印张"
          width="100"
          prop="sheet"
          align="center"
        ></el-table-column>
        <el-table-column
          label="印色"
          min-width="100"
          prop="printColor"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_order_print_color"
              :value="scope.row.printColor"
            />
          </template>
        </el-table-column>
        <el-table-column label="颜色" width="120" prop="color" align="center">
          <template #default="scope">
            <dict-tag :options="ems_produce_color" :value="scope.row.color" />
          </template>
        </el-table-column>

        <el-table-column
          label="用纸尺寸"
          prop="paperSize"
          min-width="135"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_produce_paper_size"
              :value="scope.row.paperSize"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="成品尺寸(mm)"
          width="130"
          prop="finishSize"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_produce_finish_size"
              :value="scope.row.finishSize"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="版材尺寸"
          min-width="125"
          prop="sheetSize"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_machine_info_size"
              :value="scope.row.sheetSize"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="纸型"
          width="120"
          prop="paperType"
          align="center"
        >
          <template #default="scope">
            <dict-tag :options="mes_paper_type" :value="scope.row.paperType" />
          </template>
        </el-table-column>
        <el-table-column
          label="纸张编码"
          width="120"
          prop="paperNo"
          align="center"
        ></el-table-column>
        <el-table-column
          label="纸张名称"
          min-width="160"
          prop="paperName"
          align="center"
        />
        <el-table-column
          label="用版数量"
          width="100"
          prop="boardsCount"
          align="center"
        ></el-table-column>
        <el-table-column
          label="清样编号"
          min-width="120"
          prop="sampleNo"
          align="center"
        ></el-table-column>

        <el-table-column label="烤版" width="100" prop="kaoban" align="center">
          <template #default="scope">
            {{
              scope.row.kaoban == 1 ? "是" : scope.row.kaoban == 2 ? "否" : ""
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="产品序列号"
          min-width="120"
          prop="productNo"
          align="center"
        ></el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog v-model="dialogTableVisible" title="印刷管理" width="70%">
      <el-table
        :data="PrintingManagementList"
        row-key="printId"
        ref="producePrintListRef"
        border
      >
        <el-table-column label="序号" width="60" type="index" align="center" />
        <el-table-column
          label="品种"
          prop="breed"
          min-width="160"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="组成"
          min-width="160"
          prop="composition"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="印张"
          width="100"
          prop="sheet"
          align="center"
        ></el-table-column>

        <el-table-column
          label="贴标"
          width="120"
          prop="labeling"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="印数"
          width="120"
          prop="printAmount"
          align="center"
        ></el-table-column>
        <el-table-column
          label="用纸令数"
          width="120"
          prop="reamAmount"
          align="center"
        ></el-table-column>
        <el-table-column
          label="损耗系数"
          width="100"
          prop="lossCoefficient"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="损耗令数"
          width="120"
          prop="lossReam"
          align="center"
        ></el-table-column>
        <el-table-column
          label="用纸总令数"
          width="120"
          prop="totalReamAmount"
          align="center"
        ></el-table-column>

        <el-table-column
          label="吨位系数"
          width="120"
          prop="tonnageCoefficient"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="印刷方式"
          prop="printType"
          width="120"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="mes_paper_package"
              :value="scope.row.printType"
            />
          </template>
        </el-table-column>

        <el-table-column
          label="轮转吨数"
          width="120"
          prop="rotateTon"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="版材尺寸"
          prop="sheetSize"
          min-width="125"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_machine_info_size"
              :value="scope.row.sheetSize"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="另行加放"
          width="120"
          prop="lxjf"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="成品尺寸"
          width="120"
          prop="finishSize"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="ems_produce_finish_size"
              :value="scope.row.finishSize"
            />
          </template>
        </el-table-column>

        <el-table-column
          label="工艺"
          min-width="160"
          prop="technologyId"
          align="center"
        >
          <template #default="scope">
            <el-select
              disabled
              clearable
              style="width: 100%"
              v-model="scope.row.technologyId"
              placeholder="请选择工艺"
            >
              <el-option
                v-for="item in technologyList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          label="印刷"
          min-width="120"
          prop="printMachine"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="半代裁切"
          min-width="120"
          prop="whitecuttingMachine"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="封面裁切"
          min-width="120"
          prop="covercuttingMachine"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="覆膜"
          min-width="120"
          prop="coveringMachine"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="折页"
          min-width="120"
          prop="foldMachine"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="装订"
          min-width="120"
          prop="bindingMachine"
          align="center"
        >
        </el-table-column>
        <el-table-column
          label="纸张规格"
          width="120"
          prop="paperSpecifications"
          align="center"
        >
          <template #default="scope">
            <dict-tag
              :options="mes_paper_specs"
              :value="scope.row.paperSpecifications"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="下单印数"
          width="120"
          prop="orderPrintCount"
          align="center"
        >
        </el-table-column>

        <el-table-column
          label="纸型"
          width="120"
          prop="paperType"
          align="center"
        >
          <template #default="scope">
            <dict-tag :options="mes_paper_type" :value="scope.row.paperType" />
          </template>
        </el-table-column>
        <el-table-column
          label="定量"
          min-width="120"
          prop="weight"
          align="center"
        ></el-table-column>
        <el-table-column
          label="幅宽"
          width="120"
          prop="clothWidth"
          align="center"
        ></el-table-column>
        <el-table-column label="品牌" width="120" prop="brand" align="center">
        </el-table-column>
        <el-table-column
          label="印刷序列号"
          min-width="120"
          prop="printProduceNo"
          align="center"
        ></el-table-column>
        <el-table-column
          label="备注"
          width="120"
          prop="remark"
          fixed="right"
          align="center"
        >
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script setup name="Order">
const activeName = ref("first");
import { downLoad, toNumber } from "@/utils/ruoyi";
import { getTechnologyList } from "@/api/production/technics.js";
import {
  getProduceOrderList,
  updatebookNo,
  getProduceById,
} from "@/api/production/cover";
const { proxy } = getCurrentInstance();
const { mes_paper_package } = proxy.useDict("mes_paper_package");
const loading = ref(true);
const paperLoading = ref(false);
const loadingList = ref(false);
const dataList = ref([]);
const showSearch = ref(true);
const total = ref(0);
const advanced = ref(false);
const countTotal = ref(0);
const multiple = ref(true);
const produceProductList = ref([]);
const PrintingManagementList = ref([]);
const selectBookNo = ref([]);
const open = ref(false);
const dialogTableVisible = ref(false);
const type = ref("");
const technologyList = ref([]);
const typeOptions = ref([
  { label: "封面", value: "1" },
  { label: "内文", value: "2" },
]);
// 列显隐信息
const columns = ref([
  { key: 0, label: `状态`, visible: true },
  { key: 1, label: `生产单编码`, visible: true },
  { key: 2, label: `新/旧版`, visible: true },
  { key: 3, label: `出版编号`, visible: true },
  { key: 4, label: `下单日期`, visible: true },
  { key: 5, label: `加急交货日期`, visible: true },
  { key: 6, label: `备注`, visible: true },
  { key: 7, label: `车间`, visible: true },
]);
const producePaperList = ref([]);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 50,
    // state: 2,
  },
});
const { queryParams } = toRefs(data);
const {
  ems_produce_book_size,
  ems_order_binding_mode,
  ems_machine_info_size,
  ems_produce_finish_size,
  ems_order_print_color,
  ems_produce_color,
  ems_produce_paper_size,
  ems_produce_cover_film,
  ems_produce_marking,
  produce_text_printer,
  mes_paper_type,
  mes_paper_unit,
  mes_paper_specs,
  mes_paper_material,
  ems_workshop_subject_type,
  ems_order_status,
  ems_produce_is_new,
  ems_workshop,
} = proxy.useDict(
  "ems_produce_book_size",
  "ems_order_binding_mode",
  "ems_machine_info_size",
  "ems_produce_finish_size",
  "ems_order_print_color",
  "ems_produce_color",
  "ems_produce_paper_size",
  "ems_produce_cover_film",
  "ems_produce_marking",
  "produce_text_printer",
  "mes_paper_type",
  "mes_paper_unit",
  "mes_paper_specs",
  "ems_order_status",
  "mes_paper_material",
  "ems_workshop_subject_type",
  "ems_produce_is_new",
  "ems_workshop"
);

const getDateNow = () => {
  var myDate = new Date();
  var year = myDate.getFullYear();
  var month = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月，所以要加1);
  var day = myDate.getDate(); //获取当前日（1-31）
  if (month < 10) {
    month = "0" + month;
  }
  if (day >= 0 && day <= 9) {
    day = "0" + day;
  }
  var firstDay = year + "-" + month + "-01";
  return firstDay;
};
const getCurrentDay = () => {
  var now = new Date();
  var year = now.getFullYear();
  var month = now.getMonth() + 1; // 月份从0开始，需要加1
  var day = now.getDate();
  if (month < 10) {
    month = "0" + month;
  }
  if (day >= 0 && day <= 9) {
    day = "0" + day;
  }
  const currentDay = year + "-" + month + "-" + day;
  return currentDay;
};
const dateRange = ref([getDateNow(), getCurrentDay()]);
const selectable = (row, index) => {
  if (row.bookNo) {
    return true;
  }
};

const onRowClick = (row) => {
  orderInfoOpen.value = true;
  orderInfoId.value = row.produceId;
};
const handleSelectionChange = (row) => {
  let producePaperListPromises = [];
  row.forEach((item) => {
    producePaperListPromises.push(
      getProduceById({ pid: item.produceId }).then((res) => {
        // console.log(res);
        // res.data.producePaperList.forEach(item=>{
        //     res.data.producePaperList.forEach(obj=>{
        //         if(item.orderProductId ==obj.orderProductId){
        //             item.sheetSize = obj.sheetSize
        //         }
        //     })
        // })
        if (res.data.type == 1) {
          res.data.producePaperList[0].sheetSize =
            res.data.producePrintList[0].sheetSize;
        }
        return res.data.producePaperList;
      })
    );
  });
  paperLoading.value = true;
  Promise.all(producePaperListPromises)
    .then((producePaperLists) => {
      producePaperList.value = producePaperLists.reduce(
        (acc, paperList) => [...acc, ...paperList],
        []
      );
      paperLoading.value = false;
      producePaperList.value = producePaperList.value.reduce((acc, current) => {
        const existingItem = acc.find(
          (item) =>
            item.paperNo === current.paperNo &&
            item.sheetSize === current.sheetSize
        );
        if (existingItem) {
          existingItem.reamAmount += current.reamAmount;
          existingItem.reamAmount = toNumber(existingItem.reamAmount, 4);
        } else {
          acc.push({ ...current });
        }
        return acc;
      }, []);
    })
    .catch((error) => {
      console.error("An error occurred:", error);
    });
};

// 合计
const getSummaries = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 1) {
      sums[index] = "合计";
      return;
    }
    switch (column.property) {
      case "orderCount":
        sums[index] = countTotal.value;
        break;
      default:
        break;
    }
  });
  return sums;
};
const getList = () => {
  loading.value = true;
  getProduceOrderList({
    ...queryParams.value,
    startTime: Array.isArray(dateRange.value) ? dateRange.value[0] : undefined,
    endTime:
      Array.isArray(dateRange.value) > 0 ? dateRange.value[1] : undefined,
  })
    .then((res) => {
      loading.value = false;
      dataList.value = res.rows;
      countTotal.value = res.rows[0].countTotal;
      total.value = res.total;
    })
    .catch((err) => {
      loading.value = false;
    });
};

// 查看
const handleView = (row) => {
  type.value = row.type;
  loadingList.value = true;
  getProduceById({ pid: row.produceId }).then((res) => {
    produceProductList.value = res.data.produceProductList;
    loadingList.value = false;
  });
  open.value = true;
};

// 查看
const handleViewys = (row) => {
  type.value = row.type;
  loadingList.value = true;
  getProduceById({ pid: row.produceId }).then((res) => {
    PrintingManagementList.value = res.data.producePrintList;
    loadingList.value = false;
  });
  dialogTableVisible.value = true;
};

const handleCancel = () => {};
// 搜索
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  producePaperList.value = [];
  dateRange.value = [getDateNow(), getCurrentDay()];
  proxy.resetForm("queryRef");
  handleQuery();
};
getList();

//  获取工艺
const getTechnologyArr = () => {
  getTechnologyList({ pageNum: 1, pageSize: 100 }).then((res) => {
    technologyList.value = res.rows;
  });
};
getTechnologyArr();
</script>

<style lang="scss" scoped></style>
